package com.xu.sms.controller;

import java.util.List;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.xu.sms.R;
import com.xu.sms.adapter.HotAdapter;
import com.xu.sms.entity.Type;
import com.xu.sms.net.HTTPNet;
import com.xu.sms.utils.LogUtil;

public class HotFragment extends Fragment {
	
	
	private ListView hot_lv_list;
	private HotAdapter hotAdapter;
	private Context context;
	private String requestUrl = "http://"+HTTPNet.servet_IP_Address+"/sms/admin/type/findTypeBigCurDate";
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_hot, null);
		hot_lv_list = (ListView) view.findViewById(R.id.hot_lv_list);
		
		hot_lv_list.setOnItemClickListener(new MyOnItemClickListener());
		context = getActivity();
		HTTPNet.requestServerForGet(handler, requestUrl);
		return view;
	}
	
	Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			if(msg.what == HTTPNet.FIND_INFO_TYPE_BIG_CUR_DATE_STATE){
				List<Type> typeList =  (List<Type>) msg.obj;
				if(hotAdapter ==null){
					hotAdapter = new HotAdapter(context,typeList);
				}
				hot_lv_list.setAdapter(hotAdapter);
			}
		}
	};
	
	class MyOnItemClickListener implements OnItemClickListener{

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			Type type = (Type)parent.getItemAtPosition(position);
			LogUtil.i(this.getClass().getSimpleName(), 60,type.getTypeId()+"——"+type.getTypeName());
			Intent intent = new Intent(context,FBOInfoActivity.class);
			intent.putExtra("typeId",type.getTypeId());
			intent.putExtra("typeName",type.getTypeName());
			startActivity(intent);
		}
		
		
	}
	
}
